import React from "react";
import { Input, Tooltip } from 'antd';
import BaseComponent from "../../redare/components/BaseComponent";
import {getMoneyStr} from "../../common/Utils";


export default class NumericInput extends BaseComponent {

  state = {value: ''};

  onChange = e => {
    const { value } = e.target;
    let _value = value.toString().replace(RegExp(",", "g"), '');
    const reg = /^-?\d*(\.\d*)?$/;
    if ((!isNaN(_value) && reg.test(_value)) || _value === '' || _value === '-') {
      this.setState({value: getMoneyStr(_value)});
    }
  };

  render() {

    return (

        <Input
          {...this.props}
          value={this.state.value}
          onChange={this.onChange}
        />
    );
  }
}